<?php
require_once (TYPEPATH  . 'type.php');			// Carbon Paper Post Type Functions
require_once (METAPATH  . 'metabox.php');		// Carbon Paper Meta Functions


/**
 * Register the buzz custom type
 */

// Version WP >= 3.0 
if($wp_version>=3.0){
	
	add_theme_support('menus');	

	function cp_post_type_buzz() {
		// Labels for post type Buzz 
		$labels = array(
			'name' => _x('Buzz', 'taxonomy general name'),
			'singular_name' => _x('Buzz Item', 'taxonomy singular name'),
			'add_new' => __('Add New', 'cp'),
			'add_new_item' => __('Add New Item','cp'),
			'edit_item' => __('Edit Item','cp'),
			'new_item' => __('New Buzz Item','cp'),
			'view_item' => __('View Item','cp'),
			'search_items' => __('Search Buzz Items','cp'),
			'not_found' =>  __('No buzz items found','cp'),
			'not_found_in_trash' => __('No buzz items found in Trash','cp'), 
			'parent_item_colon' => ''
		);
		// Register Buzz
		register_post_type( 'buzz', array( 
			'labels' => $labels,
	        'public' => true,  
	        'show_ui' => true,  
	        'capability_type' => 'post',  
	        'hierarchical' => false,  
			'taxonomies' => array('thematic', 'category', 'post_tag'),
	        'supports' => array('title', 'editor', 'thumbnail', 'comments', 'page-attributes'), 
			'rewrite' => array(
    			'slug' => 'buzz')
		));

		// Register existing taxonomy 'category'
		register_taxonomy_for_object_type('category', 'buzz');
			
		// Register new hierarchical taxonomy (like category) named 'thematic' with rewrite to 'buz/thematic' 
		register_taxonomy('thematic', 'buzz', array(
			'hierarchical' => true, 
			'label' => __('Thematics','cp'), 
			'singular_label' => __('Thematic','cp'), 
			'rewrite' => array(
    			'slug' => 'buzz/thematic'),
		));  

		// Register new hierarchical taxonomy (like category) named 'thematic' with rewrite to 'buz/thematic' 
		register_taxonomy('genre', 'buzz', array(
			'hierarchical' => false, 
			'label' => __('	Genres','cp'), 
			'singular_label' => __('Genre','cp'), 
			'rewrite' => array(
    			'slug' => 'buzz/genre'),
		));  

		// Register existing taxonomy 'post_tag'
		register_taxonomy_for_object_type('post_tag', 'buzz');
		
		// Rewrite buzz permalink with '/buzz/%year%/%monthnum%/%day%/%buzz%/' structure
		cp_rewrite_permalink('buzz');
	}

	add_action('init', 'cp_post_type_buzz');
	add_action( 'post_type_link', 'cp_post_type_permalink', 10, 4 );


	/**
	 * Add a Category column to the Buzz page
	 */
	add_filter('manage_edit-buzz_columns', 'buzz_columns');
	function buzz_columns($columns) {
	    $columns['thematic'] = __('Thematics','cp');
	    return $columns;
	}
	
	add_action('manage_posts_custom_column',  'buzz_show_columns');
	function buzz_show_columns($name) {
	    global $post;
	    switch ($name) {
	        case 'thematic':
	            $cats = get_the_term_list( $post->ID, 'thematic', '', ', ', '' );
	            echo $cats;
	    }
	}

	/* 
	 * Add new meta boxes to the pages
	 **/
	$metabox_event = new WPAlchemy_MetaBox(array
	(
		'id' => '_metabox_event', // underscore prefix hides fields from the custom fields area
		'types' => array('buzz'), // added only to custom post type "buzz"
		'title' => 'Evénement',
		'template' => METAPATH .'/meta-buzz.php',
	));
	
	$metabox_voteprofiler = new WPAlchemy_MetaBox(array
	(
		'id' => '_metabox_voteprofiler', // underscore prefix hides fields from the custom fields area
		'types' => array('buzz'), // added only to custom post type "buzz"
		'title' => 'Profiles de votes',
		'template' => INCLUDEPATH .'/plugin/vote-profiler/meta-voteprofiler.php',
	));
} 
?>